using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.CompositeUI.SmartParts;
using NUnit.Framework;
using Rhino.Mocks;
using SCSFContrib.CompositeUI.WPF.Workspaces;

namespace SCSFContrib.CompositeUI.WPF.UnitTest.Workspaces
{
	[TestFixture]
	public sealed class WorkspaceComposerTest : UnitTest
	{
		private SCSFContrib.CompositeUI.WPF.Workspaces.WorkspaceComposer<object, SmartPartInfo> _workspaceComposer;
		private IComposableWorkspace<object, SmartPartInfo> _composedWorkspace;

		protected override void SetUpCore()
		{
			base.SetUpCore();
			_composedWorkspace = Mocks.DynamicMock<IComposableWorkspace<object, SmartPartInfo>>();
			_workspaceComposer = new SCSFContrib.CompositeUI.WPF.Workspaces.WorkspaceComposer<object, SmartPartInfo>(_composedWorkspace);
		}

		[Test]
		public void InnerSmartParts_ShouldNotBeNull()
		{
			//the implementation of our WorkspaceComposer relies on an implementation detail of CAB's WorkspaceComposer and this test just ensures
			//that the assumption holds
			Assert.IsNotNull(_workspaceComposer.InnerSmartParts, "Implementation of Microsoft.Practices.CompositeUI.SmartParts.WorkspaceComposer<TSmartPart, TSmartPartInfo> may not instantiate smart part collection as a list.");
		}

		[Test]
		public void InnerSmartParts_ShouldBeEmptyByDefault()
		{
			Assert.IsEmpty(_workspaceComposer.InnerSmartParts as ICollection);
		}

		[Test]
		public void InnerSmartParts_ShouldBeModifiable()
		{
			_workspaceComposer.InnerSmartParts.Add("abc");
			Assert.AreEqual(1, _workspaceComposer.InnerSmartParts.Count);
			Assert.AreSame("abc", _workspaceComposer.InnerSmartParts[0]);
			_workspaceComposer.InnerSmartParts.Remove("abc");
			Assert.AreEqual(0, _workspaceComposer.InnerSmartParts.Count);
		}
	}
}
